package com.igda.tihbms.data;

import android.graphics.Bitmap;

import com.igda.tihbms.controllers.LogicController;

public class Craft extends GameObject {

	private static final int COUNTER_NUMBER = 10;

	private static final int CRAFT_SPRITES_COUNT = 5;

	private final LogicController logic;

	private int bulletCounter;

	public Craft(LogicController logic) {
		super(0, 0);
		this.logic = logic;
		this.bulletCounter = 0;
	}

	public void init(Bitmap image) {
		this.sprite = new Sprite(new byte[] { 0, 1, 1, 2, 2, 3, 3, 4, 4, 3, 3,
				1, 1, 0 }, image, CRAFT_SPRITES_COUNT);
	}

	public void updateCraftLocation(float posX, float posY) {
		this.updateLocation(posX, posY);
	}

	public void tick() {
		this.sprite.toNext();

		if (this.bulletCounter == COUNTER_NUMBER) {
			this.bulletCounter = 0;
			this.logic.createBullet(this.getPosX() + CRAFT_SPRITES_COUNT / 2,
					this.getPosY());
		} else {
			this.bulletCounter++;
		}
	}

	public float getWidth() {
		return this.sprite.getWidth();
	}
}
